"""
返回日志
"""
import os
import json

from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

from common.base.base_respons import retJson

@csrf_exempt
def get_logs(request):
    """
    描述：获取日志
    """
    try:
        log_filepath = os.path.join(settings.BASE_DIR, "scripts", "log_mutil.txt")
        if not os.path.exists(log_filepath):
            return HttpResponse(json.dumps({"code": 0, "msg": "日志文件不存在"}, ensure_ascii=False))
        with open(log_filepath, 'r', encoding='utf-8') as f:
            logs = f.readlines()
        return render(request, 'logs.html', {"logs": logs})

    except Exception as e:
        return HttpResponse(json.dumps({"code": 0, "msg": str(e)}, ensure_ascii=False))